package caj.springboot.model.exception;

import caj.springboot.common.ResultCode;
import caj.springboot.common.ResultCodeEnum;
import lombok.Getter;

/**
 * @description: 自定义异常基类
 * @author: CAJ
 * @time: 2023/8/28 23:38
 */
@Getter
public class BaseException extends RuntimeException {

    private ResultCodeEnum resultCodeEnum = ResultCodeEnum.BASE_ERROR;

    private String message;

    // 最好还是不直接调用无参构造方法，不好定位问题
    public BaseException() {
        this.message = resultCodeEnum.getMsg();
    }

    // 优先使用这种异常抛出，方便定位问题
    public BaseException(String message) {
        this.message = message;
    }

    public BaseException(ResultCodeEnum resultCodeEnum) {
        this.resultCodeEnum = resultCodeEnum;
        this.message = resultCodeEnum.getMsg();
    }

    public BaseException(ResultCodeEnum resultCodeEnum, String message) {
        this.resultCodeEnum = resultCodeEnum;
        this.message = message;
    }
}
